package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IHomeService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.HomePageResponse;
import com.mall.user.annotation.Anoymous;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/shopping")
public class HomePageController {
    @Reference(timeout = 3000,retries = 0,check = false)//服务超时重试设置
    IHomeService iHomeService;//引用暴露接口

    @GetMapping("/homepage")
    @Anoymous //表示不需要进行令牌验证
    public ResponseData homePage(){
        //无参请求无需new request，也不需要进行参数验真
        HomePageResponse homePageResponse = iHomeService.homepage();
        //对服务应用返回的进行状态码验证，不对则 ，对则 。
        if(!ShoppingRetCode.SUCCESS.getCode().equals(homePageResponse.getCode())){
            //该util会自动填充ResponseData
           return new ResponseUtil().setErrorMsg(homePageResponse.getMsg());
        }//没问题就返回响应dto即可。
        return new ResponseUtil().setData(homePageResponse.getPanelContentItemDtos());
    }
}
